package com.game.grid;

import javax.microedition.khronos.opengles.GL10;

import com.mcodesal.framework.utils.LabelMaker;
import com.mcodesal.framework.utils.MsPerFrameCounter;
import com.mcodesal.framework.utils.NumericSprite;

import android.graphics.Paint;

/**
 * This class adds one more layer above our LabelMaker class so that
 * we now just make one call in our GameRenderer class to render all the GUI.
 * 
 * @author Matias
 *
 */
public class GUIRenderer {

	private Paint mLabelPaint;
	private LabelMaker mLabels;
	public NumericSprite mScoreValue;
	public MsPerFrameCounter mMsPF;
	private boolean debugMode = true;
	private int mScoreLabel;
	private int mScreenWidth;
	private int mScreenHeight;
	
	public GUIRenderer() {
		mLabelPaint = new Paint();
        mLabelPaint.setTextSize(16);
        mLabelPaint.setAntiAlias(true);
        mLabelPaint.setARGB(0xff, 0xff, 0x00, 0x00);
        mMsPF = new MsPerFrameCounter();
		
	}
	/**
	 * Goes inside onSurfaceChanged method in our GameRenderer.
	 * @param gl
	 */
	public void initialize(GL10 gl, int width, int height) {
		mScreenWidth = width;
		mScreenHeight = height;
		if (mLabels != null) {
            mLabels.shutdown(gl);
        } else {
            mLabels = new LabelMaker(true, 256, 64);
        }
		mLabels.initialize(gl);
		mLabels.beginAdding(gl);
        mScoreLabel = mLabels.add(gl, "Score:", mLabelPaint);
        mLabels.endAdding(gl);
        
        if (mScoreValue != null) {
            mScoreValue.shutdown(gl);
        } else {
            mScoreValue = new NumericSprite();
        }
        mScoreValue.initialize(gl, mLabelPaint);
        
        mMsPF.initialize(gl, mScreenWidth, mScreenHeight);
        
	}
	
	public void draw(GL10 gl) {

		mLabels.beginDrawing(gl, mScreenWidth, mScreenHeight);
		mLabels.draw(gl, 0, 450, mScoreLabel);
        mLabels.endDrawing(gl);
        
        mScoreValue.draw(gl, 50, 450, mScreenWidth, mScreenHeight);
        
        if(debugMode) {
        	mMsPF.draw(gl);
        }

	}
}
